package cn.chinaflame.pagodas.web;

import cn.chinaflame.pagodas.Result.Result;
import cn.chinaflame.pagodas.annotation.ApiDoc;
import cn.chinaflame.pagodas.constant.Sysconst;
import cn.chinaflame.pagodas.req.PaydataReq;
import cn.chinaflame.pagodas.service.PayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import cn.chinaflame.pagodas.Result.Result;
import cn.chinaflame.pagodas.entity.Boy;
import cn.chinaflame.pagodas.repository.BoyRepository;
import cn.chinaflame.pagodas.service.BoyService;
import cn.chinaflame.pagodas.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
/**
 * 佛龛支付相关接口
 *
 * @author admin
 */
@RestController
@Transactional(rollbackFor = Exception.class)
@RequestMapping(value = "openapi/v1/pagodas/pay/")
public class OpenPayAPI {
    private static Logger log = LoggerFactory.getLogger(OpenPayAPI.class);
    @Autowired
    private PayService payService;
//    @Autowired
//    private YanwuPayService yanwuPayService;

    /**
     * H5支付接口
     *
     * @param req
     * @param request
     * @return
     */
    @PostMapping(value = "order")
    @ApiDoc(PaydataReq.class)
    public Object unifiedOrder(@RequestBody PaydataReq req, HttpServletRequest request) {
        log.info("支付req:{}", req);
        req.setUserId(req.getUserId() + Sysconst.PROJECT_PAY_USERID);
//		String rs = yanwuPayService.unifiedOrder(req,request);// payService.unifiedOrder(req);
        String rs = payService.unifiedOrder(req);
        log.info("下单支付返回结果result:{}", rs);
        return Result.create(rs);
    }

    
    
    
    
    
    
    
    
    
    
    
    
    /**
     * 退款接口
     *
     * @param serialno 流水号
     * @param amount   金额
     * @return
     */
    @PostMapping(value = "order/refund")
    @ApiDoc(Result.class)
    public Object refund(@RequestParam String serialno, @RequestParam String amount) {
        log.info("退款oldorderId:{},amount:{}", serialno, amount);
//    	return yanwuPayService.refund(oldorderId,amount);
        return payService.refund(serialno, amount);
    }
}